import React, { Component } from 'react'
import './Header.css'
export default class Header extends Component {
  handle = (e) => {
    if (e.keyCode !== 13) return
    const todoName = e.target.value.trim()
    //判断用户是否输入,如果没有输入,或输入了一堆空格,则直接return
    if (!todoName) return
    // 调用父组件传过来的函数,是为了将todoName传递到App组件中
    this.props.getTodoName(todoName)
    // 清空文本框
    e.target.value = ''
  }
  render() {
    return (
      <div className="todo-header">
        <input type="text" onKeyDown={this.handle} />
      </div>
    )
  }
}
